package com.jason.annotation;

import org.junit.Test;

import java.lang.annotation.Annotation;

/**
 * @Author: Jason
 * @Date: 16/6/8
 * @Time: 11:38
 */
public class MyAnnotationJunit {


    // 获取MyAnnotationTest的getName方法里所有的注解
    @Test
    public void test1() throws ClassNotFoundException, NoSuchMethodException {
        Annotation[] annotations = Class.forName("com.jason.annotation.MyAnnotationTest").getMethod("getName").getAnnotations();
        // 编译所有注解
        for (Annotation annotation : annotations) {
            System.out.println(annotation);

            // 获取注解中的元数据
            if (annotation instanceof MyAnnotation) {
                System.out.println("tag----name---->" + ((MyAnnotation) annotation).name());
                System.out.println("tag----age---->" + ((MyAnnotation) annotation).age());
                System.out.println("tag----address---->" + ((MyAnnotation) annotation).address());
            }
        }
    }
}
